package ru.vms.healthcontrol;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import pro.notum.mobile.R;
import android.content.Context;

public class ValueUnderControl {

	public final static int WEIGHT = 1001;
	
	public enum ValueType {
		WEIGHT
	}
	
	
	public final static String WEIGHT_NAME = "weight";
	
	
	protected String mShowName;
	protected String mDescription;
	protected String mDimension;
	protected float mValue;
	protected float mChangeDelta;	
	
	
	
	protected float mLocalMinimum;
	protected float mLocalMaximum;
	protected Date mModify;
	
	protected float mPossibleMinimum;
	protected float mPossibleMaximum;

	
	protected ValueUnderControl ( ) {
	}
	
	public void set ( float v, float from, float to, Date dt ) {
		this.mValue = v;
		this.mLocalMinimum = from;
		this.mLocalMaximum = to;
		this.mModify = dt;
	}
	
	public static ValueUnderControl create ( ValueType type, Context c ) {
		
		ValueUnderControl value = new ValueUnderControl();
		
		switch (type) {
		case WEIGHT:
			value.mShowName = WEIGHT_NAME;
			value.mDescription = c.getString(R.string.weight);
			value.mDimension = c.getString(R.string.weight_dimen);
			value.mPossibleMinimum = 0.0f;
			value.mPossibleMaximum = 300.0f;
			value.mLocalMaximum = value.mPossibleMaximum;
			value.mLocalMinimum = value.mPossibleMinimum;
			value.mChangeDelta = 0.100000f;
			break;

		default:
			value = null;
			break;
		}
		
		return value;
	}

	public String getName() {
		return mShowName;
	}
	
	public String getDescr() {
		return mDescription;
	}

	public String getDimension() {
		return mDimension;
	}

	public float getValue() {
		return mValue;
	}
	
	public String getValueString() {
		return String.format(Locale.UK,"%.2f", mValue);
	}

	public float getValue_from() {
		return mLocalMinimum;
	}

	public float getValue_to() {
		return mLocalMaximum;
	}

	public void increment() {
		this.mValue += this.mChangeDelta;
	}

	public void decrement() {
		this.mValue -= this.mChangeDelta;		
	}

	public void setValue(float parseFloat) {
		this.mValue = parseFloat;
	}

	public Date getModify() {
		return mModify;
	}

	public void setModify(Date modify) {
		this.mModify = modify;
	}
	
	public String getDateStrForDb () {
		return new SimpleDateFormat("dd.MM.yyyy").format(mModify);
	}
	
	public long getDateLongForDb () {
		return Long.parseLong(getDateStrForDb());
	}

	public String getDateLongStrForDb() {
		return new SimpleDateFormat("yyyyMMdd").format(mModify);
	}

	public void setFromDb(String nm, float val, Date dt) {
		this.mValue = val;
		this.mModify = dt;
		this.mShowName = nm;

		
		this.mLocalMinimum = 0.0f;
		this.mLocalMaximum = 0.0f;
		
	}

	@Override
	public String toString() {
		return  getDateStrForDb() +" " + mShowName + " = " + mValue;
	}
	
}
